#ifndef NETSTATEXT_H
#define NETSTATEXT_H

#include <QObject>
#include <QThread>
#include <QMap>
#include <QList>
#include <QStringList>
#include <QDir>
#include <QRegExp>
#include <QTextStream>

#include "netstat.h"
#include "netstatitemmodel.h"
#include "netstatlistmodel.h"

class NetStatProc: public QThread
{
    Q_OBJECT

    NetStat *netstat;
    QString flPacket;
    bool flResolve;
    bool flDesktopFilesInfo;
    QList<QMap<QString, QVariant>*> listOut;
    QList<QMap<QString, QString>*> __listDesktopFiles;
public:
    explicit NetStatProc(QObject *parent = 0);
    ~NetStatProc();
    void setParam( const bool _flResolve = false ); //rename setResolve()
    void desktopFilesInfo( const bool isGetInfo ) { flDesktopFilesInfo = isGetInfo; }
    inline void needTCP() { flPacket = "tcp"; }
    inline void needUDP() { flPacket = "udp"; }
    inline QList<QMap<QString, QVariant>*> getResult() const { return listOut; }
    inline void workNetStat() { netstat->workNetStat(); }
    inline void tryStopNetStat() { netstat->tryStopNetStat(); }
    void getInfoDesktopFiles();
    inline QList<QMap<QString, QString>*> getResultDesktopFiles() const { return __listDesktopFiles; }

protected:
    virtual void run();

signals:

public slots:
};


struct NetStateH
{
    QString pic;
    QString txt;
};

struct ParamAppN950
{
    QString name;
    QString icon;
};

class NetStatExt : public QObject
{
    Q_OBJECT

    QObject *parent;
    QObject* pageNetworkConnections;

    NetStatListModel *listModel;

    bool flResolve;
    QString flPacket;
    QList<QMap<QString, QVariant>*> data;
    QList<QMap<QString, QString>*> listDesktopFiles;

    NetStatProc *procNetStat;

    NetStateH  netSateHuman( const QString &state ) const;
    QString descrNetState( const QString &state) const;
    ParamAppN950 findAppN950( const QString &path) const;
    ParamAppN950 predefineAppN9( const QString &path) const;

    void clearListResult();
    void clearListDesktop();
public:
    explicit NetStatExt(QObject *parent = 0);
    ~NetStatExt();
    void getData();
    
signals:
    
public slots:
    Q_INVOKABLE void initData() { flPacket = "tcp"; flResolve = false; getData(); }
    Q_INVOKABLE void resolveOnOff( const bool checked ) { flResolve = checked; this->getData(); }
    Q_INVOKABLE void tcpView() { flPacket = "tcp"; this->getData(); }
    Q_INVOKABLE void udpView() { flPacket = "udp"; this->getData(); }
    Q_INVOKABLE void stopNetstat() { procNetStat->tryStopNetStat(); }
    Q_INVOKABLE void refreshData() { this->getData(); }

private slots:
    void startNetstat();
    void finishNetstat();
    
};

#endif // NETSTATEXT_H
